﻿namespace DimensionsHelper.LanguageService.Syntax;

public abstract class BodiedStatement : Statement
{
    private Block _body;

    internal BodiedStatement(SyntaxKinds kind, SyntaxNode? parent) :
        base(kind, parent)
    {
        _body = Block.Default;
    }


    public Block Body => _body;


    public BodiedStatement Update(Block body)
    {
        SetChildField(ref _body, Block.IsEmptyOrDefault, body);
        return this;
    }


    public override void AcceptVisitor<T>(SyntaxNodeVisitor<T> visitor)
    {
        Accept(visitor, Body);

        if (!visitor.IsFinished && this is T target && visitor.Predicate(target))
        {
            visitor.Finish(this);
        }
    }
}